#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QtGlobal>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    GetAvailablePort(ui->comboBox);
    GetAvailablePort(ui->comboBox_2);
    GetAvailablePort(ui->comboBox_3);

    GetAvailablePort(ui->comboBox_4);
    GetAvailablePort(ui->comboBox_5);
    GetAvailablePort(ui->comboBox_6);
    GetAvailablePort(ui->comboBox_7);
    GetAvailablePort(ui->comboBox_19);
    GetAvailablePort(ui->comboBox_10);

    QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
    set.beginGroup("Value");
    QString value=set.value("port1").toString();
    if(ui->comboBox_4->findText(value)!=-1)
    {
        ui->comboBox_4->setCurrentText(value);
    }

    value=set.value("port2").toString();
    if(ui->comboBox_5->findText(value)!=-1)
    {
        ui->comboBox_5->setCurrentText(value);
    }

    value=set.value("port3").toString();
    if(ui->comboBox_6->findText(value)!=-1)
    {
        ui->comboBox_6->setCurrentText(value);
    }
    value=set.value("port4").toString();
    if(ui->comboBox_7->findText(value)!=-1)
    {
        ui->comboBox_7->setCurrentText(value);
    }

    value=set.value("portad").toString();
    if(ui->comboBox_19->findText(value)!=-1)
    {
        ui->comboBox_19->setCurrentText(value);
    }

    value=set.value("portswitch").toString();
    if(ui->comboBox_10->findText(value)!=-1)
    {
        ui->comboBox_10->setCurrentText(value);
    }
    SlotsInit();
    switchControl.StartTimer();

    showGrayBumb(1);
    showGrayBumb(2);

}

MainWindow::~MainWindow()
{
    qDebug()<<"~MainWindow";
    timer.stop();
    adCollector.StopTimer();
    switchControl.StopTimer();
    delete ui;
}

void MainWindow::SlotsInit()
{
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(OpenPort()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(HandleGetADValue()));
    connect(&adCollector,SIGNAL(Signal_ToShowValue(float *)),this,SLOT(ShowAdValue(float *)));
    connect(&switchControl,SIGNAL(Signal_ToShowBumb(int)),this,SLOT(ShowBumb(int)));

    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(OpenSwitchControlDevice()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(OpenSwitch1()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(OpenSwitch2()));
    connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(OpenSwitch3()));
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(OpenSwitch4()));
    connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(CloseSwitch1()));
    connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(CloseSwitch2()));
    connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(CloseSwitch3()));
    connect(ui->pushButton_11,SIGNAL(clicked()),this,SLOT(CloseSwitch4()));
    connect(ui->pushButton_12,SIGNAL(clicked()),this,SLOT(GetSwitchInputValue()));
    connect(ui->pushButton_13,SIGNAL(clicked()),this,SLOT(GetSwitchControlValue()));
    connect(ui->pushButton_14,SIGNAL(clicked()),this,SLOT(OpenDevice()));
    // connect(ui->pushButton_15,SIGNAL(clicked()),this,SLOT(SendFc6ToDevice()));
    connect(ui->pushButton_16,SIGNAL(clicked()),this,SLOT(Start()));
    connect(ui->pushButton_17,SIGNAL(clicked()),this,SLOT(CurrentMode()));
    connect(ui->pushButton_35,SIGNAL(clicked()),this,SLOT(VoltageMode()));

    connect(ui->pushButton_15,SIGNAL(clicked()),this,SLOT(ZeroVerify()));
    connect(ui->radioButton,SIGNAL(clicked()),this,SLOT(SetWitchDeviceToTest()));
    connect(ui->radioButton_2,SIGNAL(clicked()),this,SLOT(SetWitchDeviceToTest()));
    connect(ui->radioButton_3,SIGNAL(clicked()),this,SLOT(SetWitchDeviceToTest()));
    connect(ui->pushButton_19,SIGNAL(clicked()),this,SLOT(GetReady()));


    connect(&timer,SIGNAL(timeout()),this,SLOT(TimerTimeOut2()));


    connect(ui->checkBox,SIGNAL(clicked()),this,SLOT(StartAsk()));
}

void MainWindow::GetAvailablePort(QComboBox *controlItem)
{
    for(QSerialPortInfo x: QSerialPortInfo::availablePorts())
    {
        controlItem->addItem(x.portName());
    }
}

void MainWindow::TableWidgetAddRow(QString valueStr,int channel,QColor color)
{
    ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
    QDateTime time=QDateTime::currentDateTime();
    QTableWidgetItem *M=new QTableWidgetItem();
    M->setText(time.toString("yyyy-MM-dd hh:mm:ss"));
    ui->tableWidget->setVerticalHeaderItem(ui->tableWidget->rowCount()-1,M);
    if(channel==3)
    {
        ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,0,new QTableWidgetItem());
        ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,1,new QTableWidgetItem());
        ui->tableWidget->item(ui->tableWidget->rowCount()-1,0)->setText(valueStr);
        ui->tableWidget->item(ui->tableWidget->rowCount()-1,1)->setText(valueStr);

        ui->tableWidget->item(ui->tableWidget->rowCount()-1,0)->setForeground(color);
        ui->tableWidget->item(ui->tableWidget->rowCount()-1,1)->setForeground(color);
    }
    else if(channel==2)
    {
        ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,1,new QTableWidgetItem());
        ui->tableWidget->item(ui->tableWidget->rowCount()-1,1)->setText(valueStr);
    }
    else if(channel==1)
    {
        ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,0,new QTableWidgetItem());
        ui->tableWidget->item(ui->tableWidget->rowCount()-1,0)->setText(valueStr);
    }
    ui->tableWidget->resizeColumnsToContents();
    ui->tableWidget->scrollToBottom();
}

void MainWindow::TableWidget2AddRow(QString valueStr, int channel,QColor color)
{
    ui->tableWidget_2->setRowCount(ui->tableWidget_2->rowCount()+1);
    QDateTime time=QDateTime::currentDateTime();
    QTableWidgetItem *M=new QTableWidgetItem();
    M->setText(time.toString("yyyy-MM-dd hh:mm:ss"));
    ui->tableWidget_2->setVerticalHeaderItem(ui->tableWidget_2->rowCount()-1,M);
    if(channel==3)
    {
        ui->tableWidget_2->setItem(ui->tableWidget_2->rowCount()-1,0,new QTableWidgetItem());
        ui->tableWidget_2->setItem(ui->tableWidget_2->rowCount()-1,1,new QTableWidgetItem());
        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,0)->setText(valueStr);
        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,1)->setText(valueStr);

        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,0)->setForeground(color);
        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,1)->setForeground(color);
    }
    else if(channel==2)
    {
        ui->tableWidget_2->setItem(ui->tableWidget_2->rowCount()-1,1,new QTableWidgetItem());
        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,1)->setText(valueStr);
    }
    else if(channel==1)
    {
        ui->tableWidget_2->setItem(ui->tableWidget_2->rowCount()-1,0,new QTableWidgetItem());
        ui->tableWidget_2->item(ui->tableWidget_2->rowCount()-1,0)->setText(valueStr);
    }
    ui->tableWidget_2->resizeColumnsToContents();
    ui->tableWidget_2->scrollToBottom();
}

int MainWindow::GetNextPartToVerify()
{
    //return 1;
    switchControl.locker.lock();
    int ret=0;
    if(currentPart==1)
    {
        if(switchControl.right.count()>0)
        {
            switchControl.right.clear();
            ret=2;
        }
        else if(switchControl.left.count()>0)
        {
            switchControl.left.clear();
            ret= 1;
        }
        else
            ret=0;
    }
    else if(currentPart==2)
    {
        if(switchControl.left.count()>0)
        {
            switchControl.left.clear();
            ret= 1;
        }
        else if(switchControl.right.count()>0)
        {
            switchControl.right.clear();
            ret= 2;
        }
        else
            ret=0;
    }
    else
    {
        if(switchControl.left.count()>0)
        {
            switchControl.left.clear();
            ret= 1;
        }
        else if(switchControl.right.count()>0)
        {
            switchControl.right.clear();
            ret= 2;
        }
        else
            ret= 0;
    }
    switchControl.locker.unlock();
    if(ret==1)
    {
        showGrayBumb(1);
    }
    else if(ret==2)
        showGrayBumb(2);
    return ret;
}

void MainWindow::ShowTestFailed(int widgetIndex,QString value)
{
    QTableWidget* tmp=nullptr;

    if(widgetIndex==1)
        tmp=ui->tableWidget;
    else if(widgetIndex==2)
        tmp=ui->tableWidget_2;

    QDateTime time=QDateTime::currentDateTime();

    tmp->setRowCount(tmp->rowCount()+1);

    QTableWidgetItem *item1=new QTableWidgetItem();
    item1->setText(time.toString("yyyy-MM-dd hh:mm:ss"));
    tmp->setVerticalHeaderItem(tmp->rowCount()-1,item1);

    QTableWidgetItem *item=new QTableWidgetItem();
    item->setForeground(Qt::red);
    item->setText(value);
    tmp->setItem(tmp->rowCount()-1,0,item);

    tmp->resizeColumnsToContents();
    tmp->scrollToBottom();
}
//此接口为第一次校验不通过第二次校验才调用的接口
short MainWindow::ReVerify0(float targetvalue,float value1,short step1,float value2,short step2)
{
    //Q_UNUSED(step1)
    float k=(value2-value1)/step2;
    short recv=0;
    recv=(targetvalue-value2)/k;
    return recv;
}

void MainWindow::showGrayBumb(int value)
{
    if(value==1)
    {
        QImage m(":picture/gray.jpeg");
        m=m.scaledToWidth(ui->label_23->width());
        ui->label_23->setPixmap(QPixmap::fromImage(m));
    }
    else if(value==2)
    {
        QImage m(":picture/gray.jpeg");
        m=m.scaledToWidth(ui->label_24->width());
        ui->label_24->setPixmap(QPixmap::fromImage(m));
    }
}

void MainWindow::SetWitchDeviceToTest()
{

    if(ui->radioButton->isChecked())
    {
        device1ShouldTest=true;
        device2ShouldTest=true;
    }
    else if(ui->radioButton_2->isChecked())
    {
        device1ShouldTest=true;
        device2ShouldTest=false;
    }
    else if(ui->radioButton_3->isChecked())
    {
        device2ShouldTest=true;
        device1ShouldTest=false;
    }
}

bool MainWindow::HaveTryTime(int channel, int zero)
{
    if(channel==1&&zero==1)
    {    if(tryTimes11>0)
        {
            tryTimes11--;
            return  true;
        }
        else
            return false;
    }

    if(channel==1&&zero==2)
    {    if(tryTimes12>0)
        {
            tryTimes12--;
            return  true;
        }
        else
            return false;
    }

    if(channel==2&&zero==1)
    {    if(tryTimes21>0)
        {
            tryTimes21--;
            return  true;
        }
        else
            return false;
    }

    if(channel==2&&zero==2)
    {    if(tryTimes22>0)
        {
            tryTimes22--;
            return  true;
        }
        else
            return false;
    }
    return  false;
}

int MainWindow::GoToStep(int channel, int zero)
{
    if(channel==1&&zero==1)
    {
        return 12;
    }
    else if(channel==1&&zero==2)
    {
        return 18;
    }
    else if(channel==2&&zero==1)
    {
        return 25;
    }
    else if(channel==2&&zero==2)
    {
        return 31;
    }
    return 0;
}


void MainWindow::ChooseAOrBToTest()
{
    currentPart=GetNextPartToVerify();
    if(currentPart==1)
    {
        Device1=&DeviceA1;
        Device2=&DeviceA2;
        steps=1;
        if(device1ShouldTest)
            TableWidgetAddRow("选取A组测试",3);
        if(device2ShouldTest)
            TableWidget2AddRow("选取A组测试",3);

    }
    else if(currentPart==2)
    {
        Device1=&DeviceB1;
        Device2=&DeviceB2;
        steps=1;
        if(device1ShouldTest)
            TableWidgetAddRow("选取B组测试",3);
        if(device2ShouldTest)
            TableWidget2AddRow("选取B组测试",3);
    }
}


void MainWindow::ChooseAOrBToTest2()
{
    currentPart=GetNextPartToVerify();
    if(currentPart==1)
    {
        TableWidgetIsClear();
        tryTimes11=2;
        tryTimes12=2;
        tryTimes21=2;
        tryTimes22=2;

        Device1=&DeviceA1;
        Device2=&DeviceA2;
        testStep=1;
        if(device1ShouldTest)
            TableWidgetAddRow("选取A组测试",3);
        if(device2ShouldTest)
            TableWidget2AddRow("选取A组测试",3);

    }
    else if(currentPart==2)
    {
        TableWidgetIsClear();
        Device1=&DeviceB1;
        Device2=&DeviceB2;
        testStep=1;
        if(device1ShouldTest)
            TableWidgetAddRow("选取B组测试",3);
        if(device2ShouldTest)
            TableWidget2AddRow("选取B组测试",3);
    }
}


void MainWindow::BreakSwitch()
{
    if(currentPart==1)
    {
        if(device1ShouldTest)
        {
            CloseSwitch1();
            TableWidgetAddRow("断开继电器1",3);
            QThread::msleep(10);
        }

        if(device2ShouldTest)
        {
            CloseSwitch2();
            TableWidget2AddRow("断开继电器2",3);
            QThread::msleep(1000);
        }
    }
    else if(currentPart==2)
    {
        if(device1ShouldTest)
        {
            CloseSwitch3();
            TableWidget2AddRow("断开继电器3",3);
            QThread::msleep(10);
        }

        if(device2ShouldTest)
        {
            CloseSwitch4();
            TableWidget2AddRow("断开继电器4",3);
            QThread::msleep(1000);
        }

    }
}

void MainWindow::JudgeIfBreakSwitchSuccess()
{
    if(currentPart==1)
    {
        if(device1ShouldTest)
        {
            if(switchControl.controlValue.onOff[0]==false)
            {
                TableWidgetAddRow("断开继电器1成功",3);
                device1IsSuccees=true;
            }
            else
            {
                TableWidgetAddRow("断开继电器1失败",3);
                ShowTestFailed(1,"测试失败");
                device1IsSuccees=false;
            }
        }
        if(device2ShouldTest)
        {
            if(switchControl.controlValue.onOff[1]==false&&device2ShouldTest)
            {
                TableWidget2AddRow("断开继电器2成功",3);
                device2IsSuccees=true;
            }
            else
            {
                TableWidget2AddRow("断开继电器2失败",3);
                ShowTestFailed(2,"测试失败");
                device2IsSuccees=false;
            }
        }
    }
    else if(currentPart==2)
    {
        if(device1ShouldTest)
        {
            if(switchControl.controlValue.onOff[2]==false&&device1ShouldTest)
            {
                TableWidgetAddRow("断开继电器3成功",3);
                device1IsSuccees=true;
            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow("断开继电器3失败",3);
                ShowTestFailed(1,"测试失败");
            }
        }
        if(device2ShouldTest)
        {
            if(switchControl.controlValue.onOff[3]==false&&device2ShouldTest)
            {
                TableWidget2AddRow("断开继电器4成功",3);
                device2IsSuccees=true;
            }
            else
            {
                device1IsSuccees=false;
                TableWidget2AddRow("断开继电器4失败",3);
                ShowTestFailed(2,"测试失败");

            }
        }
    }
}

void MainWindow::SetDeviceRangeChannel1()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
        {
            Device1->SetChannel1Range(70);
            TableWidgetAddRow("设置通道1量程70",3);
            QThread::msleep(10);
        }
        else if(ui->comboBox_11->currentIndex()==1)
        {
            Device1->SetChannel1Range(60);
            TableWidgetAddRow("设置通道1量程60",3);
            QThread::msleep(10);
        }
    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
        {
            Device2->SetChannel1Range(70);
            TableWidget2AddRow("设置通道1量程70",3);

        }
        else if(ui->comboBox_11->currentIndex()==1)
        {
            Device2->SetChannel1Range(60);
            TableWidget2AddRow("设置通道1量程60",3);

        }
    }
}

void MainWindow::SetDeviceRangeChannel2()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
        {
            Device1->SetChannel2Range(70);
            TableWidgetAddRow("设置通道2量程70",3);
        }
        else if(ui->comboBox_11->currentIndex()==1)
        {
            Device1->SetChannel2Range(60);
            TableWidgetAddRow("设置通道2量程60",3);
        }
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        QThread::msleep(10);
        if(ui->comboBox_11->currentIndex()==0)
        {
            Device2->SetChannel2Range(70);
            TableWidget2AddRow("设置通道2量程70",3);

        }
        else if(ui->comboBox_11->currentIndex()==1)
        {
            Device2->SetChannel2Range(60);
            TableWidget2AddRow("设置通道2量程60",3);
        }
    }
}

void MainWindow::SetDeviceType()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->SetDeviceType(ui->comboBox_8->currentIndex());
        TableWidgetAddRow("设置产品选型"+ui->comboBox_8->currentText(),3);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->SetDeviceType(ui->comboBox_8->currentIndex());
        TableWidget2AddRow("设置产品选型"+ui->comboBox_8->currentText(),3);
    }
}

void MainWindow::Channel1ZeroCalibration()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->Channel1ZeroCalibration();
        TableWidgetAddRow("通道1输入零点校准",1);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel1ZeroCalibration();
        TableWidget2AddRow("通道1输入零点校准",1);
    }
}

void MainWindow::Channel2ZeroCalibration()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        TableWidgetAddRow("通道2输入零点校准",2);
        Device1->Channel2ZeroCalibration();
    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel2ZeroCalibration();
        TableWidget2AddRow("通道2输入零点校准",2);
    }
}

void MainWindow::OpenSwitch()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    if(currentPart==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            OpenSwitch1();
            TableWidgetAddRow("闭合继电器1",3);
            QThread::msleep(500);
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            OpenSwitch2();
            TableWidget2AddRow("闭合继电器2",3);
            QThread::msleep(500);
        }

    }
    else if (currentPart==2)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            OpenSwitch3();
            QThread::msleep(500);
            TableWidgetAddRow("闭合继电器3",3);

        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            OpenSwitch4();
            QThread::msleep(500);
            TableWidget2AddRow("闭合继电器4",3);
        }
    }
}

void MainWindow::Sleep2S()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    QThread::msleep(1000);
    if(device1IsSuccees&&device1ShouldTest)
        TableWidgetAddRow("休眠1s",3);
    if(device2IsSuccees&&device2ShouldTest)
        TableWidget2AddRow("休眠1s",3);
}

void MainWindow::JudgeIfOpenSwitchSuccess()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    if(currentPart==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(switchControl.controlValue.onOff[0]==true)
            {
                TableWidgetAddRow("闭合继电器1成功",3);
                device1IsSuccees=true;
                steps=11;
            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow("闭合继电器1失败",3);
                ShowTestFailed(1,"测试失败");
            }
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            if(switchControl.controlValue.onOff[1]==true)
            {
                TableWidget2AddRow("闭合继电器2成功",3);
                device2IsSuccees=true;
                steps=11;
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow("闭合继电器2失败",3);
                ShowTestFailed(2,"测试失败");
            }
        }
    }
    else if(currentPart==2)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(switchControl.controlValue.onOff[2]==true)
            {
                TableWidgetAddRow("闭合继电器3成功",3);
                device1IsSuccees=true;
                steps=11;
            }
            else
            {
                TableWidgetAddRow("闭合继电器3失败",3);
                device1IsSuccees=false;
                ShowTestFailed(1,"测试失败");

            }
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            if(switchControl.controlValue.onOff[3]==true)
            {
                TableWidget2AddRow("闭合继电器4成功",3);
                device2IsSuccees=true;
                steps=11;
            }
            else
            {
                TableWidget2AddRow("闭合继电器4失败",3);
                device2IsSuccees=false;
                ShowTestFailed(2,"测试失败");

            }
        }
    }

}

void MainWindow::Channel1VerifyFull()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    if(device1IsSuccees&&device1ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
            Device1->Channel1InputFullCalibration(7000);
        else if(ui->comboBox_11->currentIndex()==1)
            Device1->Channel1InputFullCalibration(6000);
        TableWidgetAddRow("输入通道1较满值",1);
    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
            Device2->Channel1InputFullCalibration(7000);
        else if(ui->comboBox_11->currentIndex()==1)
            Device2->Channel1InputFullCalibration(6000);
        TableWidget2AddRow("输入通道1较满值",1);
    }
}

void MainWindow::Channel2VerifyFull()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    if(device1IsSuccees&&device1ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
            Device1->Channel2InputFullCalibration(7000);
        else if(ui->comboBox_11->currentIndex()==1)
            Device1->Channel2InputFullCalibration(6000);
        TableWidgetAddRow("输入通道2较满值",2);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        if(ui->comboBox_11->currentIndex()==0)
            Device2->Channel2InputFullCalibration(7000);
        else if(ui->comboBox_11->currentIndex()==1)
            Device2->Channel2InputFullCalibration(6000);
        TableWidget2AddRow("输入通道2较满值",2);
    }
}

void MainWindow::Channel1ZeroOutPutTest(int value)
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->Channel1ZeroAdjustment(value);
        TableWidgetAddRow(QString("零点调试控制输出%0").arg(value),1);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel1ZeroAdjustment(value);
        TableWidget2AddRow(QString("零点调试控制输出%0").arg(value),1);
    }

    QThread::msleep(2000);
}

void MainWindow::GetFirstPoint(int channel)
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    firstPoint=adCollector.GetCurrentValue();
    if(device1IsSuccees&&device1ShouldTest)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==1)
            {
                readValue=firstPoint.readValue[0];
            }
            else if(channel==2)
            {
                readValue=firstPoint.readValue[2];
            }
        }
        else if(currentPart==2)
        {
            if(channel==1)
            {
                readValue=firstPoint.readValue[4];
            }
            else if(channel==2)
            {
                readValue=firstPoint.readValue[6];
            }
        }
        TableWidgetAddRow(QString("第1点获取输出电压/电流%0").arg(readValue),channel);
    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==1)
            {
                readValue=firstPoint.readValue[1];
            }
            else if(channel==2)
            {
                readValue=firstPoint.readValue[3];
            }
        }
        else if(currentPart==2)
        {
            if(channel==1)
            {
                readValue=firstPoint.readValue[5];
            }
            else if(channel==2)
            {
                readValue=firstPoint.readValue[7];
            }
        }
        TableWidget2AddRow(QString("第1点获取输出电压/电流%0").arg(readValue),channel);
    }
    steps++;
}

void MainWindow::GetSecondPoint(int channel)
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    secondPoint=adCollector.GetCurrentValue();
    if(device1IsSuccees&&device1ShouldTest)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==1)
            {
                readValue=secondPoint.readValue[0];
            }
            else if(channel==2)
            {
                readValue=secondPoint.readValue[2];
            }
        }
        else if(currentPart==2)
        {
            if(channel==1)
            {
                readValue=secondPoint.readValue[4];
            }
            else if(channel==2)
            {
                readValue=secondPoint.readValue[6];
            }
        }
        TableWidgetAddRow(QString("第2点获取输出电压/电流%0").arg(readValue),channel);
    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==1)
            {
                readValue=secondPoint.readValue[1];
            }
            else if(channel==2)
            {
                readValue=secondPoint.readValue[3];
            }
        }
        else if(currentPart==2)
        {
            if(channel==1)
            {
                readValue=secondPoint.readValue[5];
            }
            else if(channel==2)
            {
                readValue=secondPoint.readValue[7];
            }
        }
        TableWidget2AddRow(QString("第2点获取输出电压/电流%0").arg(readValue),channel);
    }
    steps++;
}

void MainWindow::Channel2ZeroOutputTest(int value)
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->Channel2ZeroAdjustment(value);
        TableWidgetAddRow(QString("零点调试控制输出%0").arg(value),2);

    }
    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel2ZeroAdjustment(value);
        TableWidget2AddRow(QString("零点调试控制输出%0").arg(value),2);
    }
    QThread::msleep(2000);
}

void MainWindow::Channel2FullOutputTest(int value)
{
    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->Channel2FullAdjustment(value);
        TableWidgetAddRow(QString("满值调试控制输出%0").arg(value),2);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel2FullAdjustment(value);
        TableWidget2AddRow(QString("满值调试控制输出%0").arg(value),2);
    }
    QThread::msleep(2000);
}

void MainWindow::Channel1ZeroOutPutVerify()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    //    QMessageBox A;
    //    A.setText(QString::number(workMode));
    //    A.show();
    //    A.exec();
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                zeroPonit1x=ReVerify0(0,firstPoint.readValue[0],1,secondPoint.readValue[0],100);
            else if(currentPart==2)
                zeroPonit1x=ReVerify0(0,firstPoint.readValue[4],1,secondPoint.readValue[4],100);

            Device1->Channel1ZeroAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                zeroPonit2x=ReVerify0(0,firstPoint.readValue[1],1,secondPoint.readValue[1],100);
            else if(currentPart==2)
                zeroPonit2x=ReVerify0(0,firstPoint.readValue[5],1,secondPoint.readValue[5],100);

            Device2->Channel1ZeroAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);
        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                zeroPonit1x=ReVerify0(4,firstPoint.readValue[0],1,secondPoint.readValue[0],100);
            else if(currentPart==2)
                zeroPonit1x=ReVerify0(4,firstPoint.readValue[4],1,secondPoint.readValue[4],100);

            Device1->Channel1ZeroAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                zeroPonit2x=ReVerify0(4,firstPoint.readValue[1],1,secondPoint.readValue[1],100);
            else if(currentPart==2)
                zeroPonit2x=ReVerify0(4,firstPoint.readValue[5],1,secondPoint.readValue[5],100);

            Device2->Channel1ZeroAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);

        }
    }
    QThread::msleep(2000);
}

void MainWindow::JudgeChannel1ZeroVerifySucess()
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }
    RecvAdValue value=adCollector.GetCurrentValue();
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            float readValue=0;

            if(currentPart==1)
                readValue=value.readValue[0];
            else if(currentPart==2)
                readValue=value.readValue[4];

            if(abs(readValue-0.00)<0.005)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功,实际读出值%0").arg(readValue),1);

            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow(QString("失败,实际读出值%0").arg(readValue),1);
                ShowTestFailed(1,"测试失败");

            }
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[1];
            else if(currentPart==2)
                readValue=value.readValue[5];

            if(abs(readValue-0.00)<0.005)
            {
                device2IsSuccees=true;
                TableWidget2AddRow(QString("成功,实际读出值%0").arg(readValue),1);
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow(QString("失败,实际读出值%0").arg(readValue),1);
                ShowTestFailed(2,"测试失败");

            }
        }
    }
    else if(workMode==1)
    {

        if(device1IsSuccees&&device1ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[0];
            else if(currentPart==2)
                readValue=value.readValue[4];

            if(abs(readValue-4)<0.016)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功，实际读出值%0").arg(readValue),1);

            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow(QString("失败，实际读出值%0").arg(readValue),1);
                ShowTestFailed(1,"测试失败");

            }
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[1];
            else if(currentPart==2)
                readValue=value.readValue[5];

            if(readValue-4<0.016)
            {
                device2IsSuccees=true;
                TableWidget2AddRow(QString("成功,实际读出值%0").arg(readValue),1);
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow(QString("失败,实际读出值%0").arg(readValue),1);
                ShowTestFailed(1,"测试失败");
            }
        }
    }
}

void MainWindow::Channel1FullOutPutTest(int value)
{
    if(device1IsSuccees==false&&device2IsSuccees==false)
    {
        steps=0;
        timer.stop();
        return;
    }

    if(device1IsSuccees&&device1ShouldTest)
    {
        Device1->Channel1FullAdjustment(value);
        TableWidgetAddRow(QString("通道1满值调试输出电压值%0").arg(value),1);
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        Device2->Channel1FullAdjustment(value);
        TableWidget2AddRow(QString("通道1满值调试输出电压值%0").arg(value),1);
    }
    QThread::msleep(2000);
}

void MainWindow::Channel1FullOutputVerify()
{
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                zeroPonit1x=ReVerify0(5,firstPoint.readValue[0],1,secondPoint.readValue[0],100);
            else if(currentPart==2)
                zeroPonit1x=ReVerify0(5,firstPoint.readValue[4],1,secondPoint.readValue[4],100);
            Device1->Channel1FullAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                zeroPonit2x=ReVerify0(5,firstPoint.readValue[1],1,secondPoint.readValue[1],100);
            else if (currentPart==2)
            {
                zeroPonit2x=ReVerify0(5,firstPoint.readValue[5],1,secondPoint.readValue[5],100);
            }
            Device2->Channel1FullAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);
        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                zeroPonit1x=ReVerify0(20,firstPoint.readValue[0],1,secondPoint.readValue[0],100);
            else if(currentPart==2)
                zeroPonit1x=ReVerify0(20,firstPoint.readValue[4],1,secondPoint.readValue[4],100);
            Device1->Channel1FullAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);

        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
            {
                zeroPonit2x=ReVerify0(20,firstPoint.readValue[1],1,secondPoint.readValue[1],100);
            }
            else if(currentPart==2)
                zeroPonit2x=ReVerify0(20,firstPoint.readValue[5],1,secondPoint.readValue[5],100);
            Device2->Channel1FullAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);

        }

    }
    QThread::msleep(2000);
}

void MainWindow::Channel2ZeroOutputVerify()
{
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)//01 23 45 67
                zeroPonit1x=ReVerify0(0,firstPoint.readValue[2],1,secondPoint.readValue[2],100);
            else if(currentPart==2)
                zeroPonit1x=ReVerify0(0,firstPoint.readValue[6],1,secondPoint.readValue[6],100);

            Device1->Channel2ZeroAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),2);
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                zeroPonit2x=ReVerify0(0,firstPoint.readValue[3],1,secondPoint.readValue[3],100);
            else if(currentPart==2)
            {
                zeroPonit2x=ReVerify0(0,firstPoint.readValue[7],1,secondPoint.readValue[7],100);
            }
            Device2->Channel2ZeroAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),2);

        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                zeroPonit1x=ReVerify0(4,firstPoint.readValue[2],1,secondPoint.readValue[2],100);
            else if(currentPart==2)
            {
                zeroPonit1x=ReVerify0(4,firstPoint.readValue[6],1,secondPoint.readValue[6],100);
            }
            Device1->Channel2ZeroAdjustment(zeroPonit1x);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),2);
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                zeroPonit2x=ReVerify0(4,firstPoint.readValue[3],1,secondPoint.readValue[3],100);
            else if(currentPart==2)
                zeroPonit2x=ReVerify0(4,firstPoint.readValue[7],1,secondPoint.readValue[7],100);
            Device2->Channel2ZeroAdjustment(zeroPonit2x);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),2);
        }
    }
    QThread::msleep(2000);

}

void MainWindow::JudgeChannelOutputVerifySuccess(int channel,int zero)
{
    RecvAdValue value=adCollector.GetCurrentValue();
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
            {
                if(channel==2)
                    readValue=value.readValue[2];
                else if(channel==1)
                    readValue=value.readValue[0];
            }
            else if(currentPart==2)
            {
                if(channel==2)
                    readValue=value.readValue[6];
                else if(channel==1)
                    readValue=value.readValue[4];
            }

            float target=0.00;
            if(zero==1)
                target=0;
            else if(zero==2)
                target=5;

            if(abs(readValue-target)<0.005)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功,通道%0零点校准%1").arg(channel).arg(readValue),channel);
            }
            else
            {
                TableWidgetAddRow(QString("失败,通道%0零点校准%1").arg(channel).arg(readValue),channel);
                if(HaveTryTime(channel,zero))
                {
                    steps=GoToStep(channel,zero);
                    return;
                }
                device1IsSuccees=false;
                ShowTestFailed(1,"测试失败");

            }
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
            {
                if(channel==2)
                    readValue=value.readValue[3];
                else if(channel==1)
                    readValue=value.readValue[1];
            }
            else if(currentPart==2)
            {
                if(channel==2)
                    readValue=value.readValue[7];
                else if(channel==1)
                    readValue=value.readValue[5];
            }

            float target=0;
            if(zero==1)
                target=0;
            else if(zero==2)
                target=5;

            if(abs(readValue-target)<0.005)
            {
                TableWidget2AddRow(QString("成功,通道%0零点校准%1").arg(channel).arg(readValue),channel);
                device2IsSuccees=true;
            }
            else
            {
                TableWidget2AddRow(QString("失败,通道%0零点校准%1").arg(channel).arg(readValue),channel);
                if(HaveTryTime(channel,zero))
                {
                    steps=GoToStep(channel,zero);
                    return;
                }
                device2IsSuccees=false;
                ShowTestFailed(2,"测试失败");
            }
        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
            {
                if(channel==2)
                    readValue=value.readValue[2];
                else if(channel==1)
                    readValue=value.readValue[0];
            }
            else if(currentPart==2)
            {
                if(channel==2)
                    readValue=value.readValue[6];
                else if(channel==1)
                    readValue=value.readValue[4];
            }
            float target=0;
            if(zero==1)
                target=4;
            else if(zero==2)
                target=20;

            if(abs(readValue-target)<0.016)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功,通道%0校准%1").arg(channel).arg(readValue),channel);
            }
            else
            {
                TableWidgetAddRow(QString("失败,通道%0校准%1").arg(channel).arg(readValue),channel);
                if(HaveTryTime(channel,zero))
                {
                    steps=GoToStep(channel,zero);
                    return;
                }
                device1IsSuccees=false;
                ShowTestFailed(1,"测试失败");
            }
        }

        if(device2IsSuccees&&device2ShouldTest)
        {
            float readValue=0;
            if(currentPart==1)
            {
                if(channel==2)
                    readValue=value.readValue[3];
                else if(channel==1)
                    readValue=value.readValue[1];
            }
            else if(currentPart==2)
            {
                if(channel==2)
                    readValue=value.readValue[7];
                else if(channel==1)
                    readValue=value.readValue[5];
            }

            float target=0;
            if(zero==1)
                target=4;
            else if(zero==2)
                target=20;

            if(abs(readValue-target)<0.016)
            {
                TableWidget2AddRow(QString("成功,通道%0校准%1").arg(channel).arg(readValue),channel);
                device2IsSuccees=true;
            }
            else
            {
                TableWidget2AddRow(QString("失败,通道%0校准%1").arg(channel).arg(readValue),channel);
                if(HaveTryTime(channel,zero))
                {
                    steps=GoToStep(channel,zero);
                    return;
                }
                device2IsSuccees=false;
                ShowTestFailed(2,"测试失败");
            }
        }
    }
    steps++;
}
void MainWindow::JudgeChannel1FullVerifySuccess()
{
    RecvAdValue value=adCollector.GetCurrentValue();
    if(workMode==0)
    {
        if(device1IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
            {
                readValue=value.readValue[0];
            }
            else if(currentPart==2)
            {
                readValue=value.readValue[4];
            }

            if(abs(readValue-5.00)<0.005)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功,通道1满值校准%0").arg(readValue),1);
            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow(QString("失败,通道1满值校准失败%0").arg(readValue),1);
                ShowTestFailed(1,"测试失败");

            }
        }
        if(device2IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
            {
                readValue=value.readValue[1];
            }
            else if(currentPart==2)
            {
                readValue=value.readValue[5];
            }

            if(abs(readValue-5.00)<0.005)
            {
                TableWidget2AddRow(QString("成功,通道1满值校准%0").arg(readValue),1);
                device2IsSuccees=true;
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow(QString("失败,通道1满值校准%0").arg(readValue),1);
                ShowTestFailed(2,"测试失败");

            }
        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[0];
            else if(currentPart==2)
                readValue=value.readValue[4];

            if(abs(readValue-20.00)<0.016)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("成功,通道1满值校准%0").arg(readValue),1);
            }
            else
            {
                TableWidgetAddRow(QString("失败,通道1满值校准%0").arg(readValue),1);
                device1IsSuccees=false;
                ShowTestFailed(1,"测试失败");
            }
        }

        if(device2IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[1];
            else if(currentPart==2)
                readValue=value.readValue[5];

            if(abs(readValue-20.00)<0.016)
            {
                TableWidget2AddRow(QString("成功,通道1满值校准%0").arg(readValue),1);
                device2IsSuccees=true;
            }
            else
            {
                TableWidget2AddRow(QString("失败,通道1满值校准%0").arg(readValue),1);
                device2IsSuccees=false;
                ShowTestFailed(2,"测试失败");
            }
        }
    }
}

void MainWindow::SaveChannel(int channel)
{
    if(device1IsSuccees&&device1ShouldTest)
    {
        if(channel==1)
        {
            Device1->SaveChannel1();
            TableWidgetAddRow("保存通道1",1);
        }
        else if(channel==2)
        {
            Device1->SaveChannel2();
            TableWidgetAddRow("保存通道2",2);
            TableWidgetAddRow("Success",3,Qt::green);
        }
    }

    if(device2IsSuccees&&device2ShouldTest)
    {
        if(channel==1)
        {
            TableWidget2AddRow("保存通道1",1);
            Device2->SaveChannel1();
        }
        else if(channel==2)
        {
            TableWidget2AddRow("保存通道2",2);
            Device2->SaveChannel2();
            TableWidget2AddRow("Success",3,Qt::green);

        }
    }
}
//AD采集8个通道，设备1通道1的零点和满值用0号通道设备2的通道1的零点和满值用1号通道。设备1的通道2的零点和满值用2号通道，设备2的通道2的零点和满值用36号通道
void MainWindow::Channel2FullOutputVerify()
{
    if(workMode==0)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
            {
                fullPointx1=ReVerify0(5.00,firstPoint.readValue[2],1,secondPoint.readValue[2],100);
            }
            else if(currentPart==2)
            {
                fullPointx1=ReVerify0(5.00,firstPoint.readValue[6],1,secondPoint.readValue[6],100);
            }
            Device1->Channel2FullAdjustment(fullPointx1);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(fullPointx1),2);
        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
            {
                fullPointx2=ReVerify0(5.00,firstPoint.readValue[3],1,secondPoint.readValue[3],100);
            }
            else if(currentPart==2)
            {
                fullPointx2=ReVerify0(5.00,firstPoint.readValue[7],1,secondPoint.readValue[7],100);
            }
            Device2->Channel2FullAdjustment(fullPointx2);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(fullPointx2),2);

        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees&&device1ShouldTest)
        {
            if(currentPart==1)
                fullPointx1=ReVerify0(20,firstPoint.readValue[2],1,secondPoint.readValue[2],100);
            else if(currentPart==2)
            {
                fullPointx1=ReVerify0(20,firstPoint.readValue[6],1,secondPoint.readValue[6],100);
            }
            Device1->Channel2FullAdjustment(fullPointx1);
            TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(fullPointx1),2);

        }
        if(device2IsSuccees&&device2ShouldTest)
        {
            if(currentPart==1)
                fullPointx2=ReVerify0(20,firstPoint.readValue[3],1,secondPoint.readValue[3],100);
            else if(currentPart==2)
                fullPointx2=ReVerify0(20,firstPoint.readValue[7],1,secondPoint.readValue[7],100);
            Device2->Channel2FullAdjustment(fullPointx2);
            TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(fullPointx2),2);

        }
    }
    QThread::msleep(2000);
}

void MainWindow::JudgeChannel2FullVerifySuccess()
{
    RecvAdValue value=adCollector.GetCurrentValue();
    if(workMode==0)
    {
        if(device1IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[2];
            else if(currentPart==2)
                readValue=value.readValue[6];
            if((readValue-5.00)<0.005)
            {
                device1IsSuccees=true;
                TableWidgetAddRow(QString("满值校准成功%0").arg(readValue),2);
            }
            else
            {
                device1IsSuccees=false;
                TableWidgetAddRow("满值校准失败",2);
            }
        }
        if(device2IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
            {
                readValue=value.readValue[3];
            }
            else if(currentPart==2)
            {
                readValue=value.readValue[7];
            }
            if(abs(readValue-5.00)<0.005)
            {
                TableWidget2AddRow(QString("满值校准成功%0").arg(readValue),2);
                device2IsSuccees=true;
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow(QString("满值校准失败%0").arg(readValue),2);
            }
        }
    }
    else if(workMode==1)
    {
        if(device1IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
            {
                readValue=value.readValue[2];
            }
            else if(currentPart==2)
            {
                readValue=value.readValue[6];
            }
            if(abs(readValue-20.00)<0.016)
            {
                device1IsSuccees=true;
                TableWidget2AddRow("满值校准成功",2);
            }
            else
            {
                device1IsSuccees=false;
                TableWidget2AddRow("满值校准失败",2);

            }
        }
        if(device2IsSuccees)
        {
            float readValue=0;
            if(currentPart==1)
                readValue=value.readValue[3];
            else if(currentPart==2)
                readValue=value.readValue[7];
            if(abs(readValue-20.00)<0.016)
            {
                TableWidget2AddRow("满值校准成功",2);
                device2IsSuccees=true;
            }
            else
            {
                device2IsSuccees=false;
                TableWidget2AddRow("满值校准失败",2);

            }
        }
    }
}

int MainWindow::Device1GoToNext()
{
    qDebug()<<"定时器槽函数当前的步骤号：innerStep1="<<innerStep1;
    if(device1IsFinish2)
    {
        if(device1IsSuccess2)
            return 0;
        else
            return 2;
    }

    switch (innerStep1)
    {
    case 1:
        BreakSwitch1Or3();
        break;
    case 2:
        If1Or3BreakSucess();
        break;
    case 3:
        SetDevice1RangeChannel1();
        break;
    case 4:
        SetDevice1RangeChannel2();
        break;
    case 5:
        SetDevice1DeviceType();
        break;
    case 6:
        Device1Channel1ZeroCalibration();
        break;
    case 7:
        Device1Channel2ZeroCalibration();
        break;
    case 8:
        Device1OpenSwitch();
        break;
    case 9:
        Device1Sleep500ms();
        break;
    case 10:
        If1Or3OpenSucess();
        break;
    case 11:
        Device1Channel1VerifyFull();
        break;
    case 12:
        Device1Channel2VerifyFull();
        break;
    case 13:
        Device1Channel1ZeroOutPutTest(1);
        break;
    case 14:
        Device1GetFirstPoint(1);
        break;
    case 15:
        Device1Channel1ZeroOutPutTest(100);
        break;
    case 16:
        Device1GetSecondPoint(1);
        break;
    case 17:
        Device1Channel1ZeroOutPutVerify();
        break;
    case 18:
        Device1JudgeChannelOutPutVerify(1,1);
        break;
    case 19:
        Device1Channel1FullOutPutTest(1);
        break;
    case 20:
        Device1GetFirstPoint(1);
        break;
    case 21:
        Device1Channel1FullOutPutTest(100);
        break;
    case 22:
        Device1GetSecondPoint(1);
        break;
    case 23:
        Device1Channel1FullOutPutVerify();
        break;
    case 24:
        Device1JudgeChannelOutPutVerify(1,2);
        break;
    case 25:
        Device1SaveChannel(1);
        break;
    case 26:
        Device1Channel2ZeroOutputTest(1);
        break;
    case 27:
        Device1GetFirstPoint(2);
        break;
    case 28:
        Device1Channel2ZeroOutputTest(100);
        break;
    case 29:
        Device1GetSecondPoint(2);
        break;
    case 30:
        Device1Channel2ZeroOutputVerify();
        break;
    case 31:
        Device1JudgeChannelOutPutVerify(2,1);
        break;
    case 32:
        Device1Channel2FullOutputTest(1);
        break;
    case 33:
        Device1GetFirstPoint(2);
        break;
    case 34:
        Device1Channel2FullOutputTest(100);
        break;
    case 35:
        Device1GetSecondPoint(2);
        break;
    case 36:
        Device1Channel2FullOutputVerify();
        break;
    case 37:
        Device1JudgeChannelOutPutVerify(2,2);
        break;
    case 38:
        Device1SaveChannel(2);
        device1IsSuccess2=true;
        device1IsFinish2=true;
        break;
    }

    innerStep1++;

    if(device1IsFinish2)
    {
        if(device1IsSuccess2)
            return 0;
        else
            return 2;
    }
    else
        return 1;

}

int MainWindow::Device2GoToNext()
{
    qDebug()<<"定时器槽函数当前的步骤号：innerStep2="<<innerStep2;

    if(device2IsFinish2)
    {
        if(device2IsSuccess2)
            return 0;
        else
            return 2;
    }

    switch (innerStep2)
    {
    case 1:
        BreakSwitch2Or4();
        break;
    case 2:
        If2OR4BreakSucess();
        break;
    case 3:
        SetDevice2RangeChannel1();
        break;
    case 4:
        SetDevice2RangeChannel2();
        break;
    case 5:
        SetDevice2DeviceType();
        break;
    case 6:
        Device2Channel1ZeroCalibration();
        break;
    case 7:
        Device2Channel2ZeroCalibration();
        break;
    case 8:
        Device2OpenSwicth();
        break;
    case 9:
        Device2Sleep500ms();
        break;
    case 10:
        If2Or4OpenSucess();
        break;
    case 11:
        Device2Channel1VerifyFull();
        break;
    case 12:
        Device2Channel2VerifyFull();
        break;
    case 13:
        Device2Channel1ZeroOutPutTest(1);
        break;
    case 14:
        Device2GetFirstPoint(1);
        break;
    case 15:
        Device2Channel1ZeroOutPutTest(100);
        break;
    case 16:
        Device2GetSecondPoint(1);
        break;
    case 17:
        Device2Channel1ZeroOutPutVerify();
        break;
    case 18:
        Device2JudgeChannelOutPutVerify(1,1);
        break;
    case 19:
        Device2Channel1FullOutPutTest(1);
        break;
    case 20:
        Device2GetFirstPoint(1);
        break;
    case 21:
        Device2Channel1FullOutPutTest(100);
        break;
    case 22:
        Device2GetSecondPoint(1);
        break;
    case 23:
        Device2Channel1FullOutPutVerify();
        break;
    case 24:
        Device2JudgeChannelOutPutVerify(1,2);
        break;
    case 25:
        Device2SaveChannel(1);
        break;
    case 26:
        Device2Channel2ZeroOutputTest(1);
        break;
    case 27:
        Device2GetFirstPoint(2);
        break;
    case 28:
        Device2Channel2ZeroOutputTest(100);
        break;
    case 29:
        Device2GetSecondPoint(2);
        break;
    case 30:
        Device2Channel2ZeroOutputVerify();
        break;
    case 31:
        Device2JudgeChannelOutPutVerify(2,1);
        break;
    case 32:
        Device2Channel2FullOutputTest(1);
        break;
    case 33:
        Device2GetFirstPoint(2);
        break;
    case 34:
        Device2Channel2FullOutputTest(100);
        break;
    case 35:
        Device2GetSecondPoint(2);
        break;
    case 36:
        Device2Channel2FullOutputVerify();
        break;
    case 37:
        Device2JudgeChannelOutPutVerify(2,2);
        break;
    case 38:
        Device2SaveChannel(2);
        device2IsSuccess2=true;
        device2IsFinish2=true;
        break;
    }

    innerStep2++;

    if(device2IsFinish2)
    {
        if(device2IsSuccess2)
            return 0;
        else
            return 2;
    }
    else
    {
        qDebug()<<"2-定时器槽函数当前的步骤号：innerStep2="<<innerStep2;
        return 1;
    }

}



void MainWindow::BreakSwitch1Or3()
{
    if(currentPart==1)
    {
        CloseSwitch1();
        TableWidgetAddRow("断开继电器1",3);
    }
    else if(currentPart==2)
    {
        CloseSwitch3();
        TableWidgetAddRow("断开继电器3",3);
    }
}

void MainWindow::BreakSwitch2Or4()
{
    if(currentPart==1)
    {
        CloseSwitch2();
        TableWidget2AddRow("断开继电器2",3);
    }
    else if(currentPart==2)
    {
        CloseSwitch4();
        TableWidget2AddRow("断开继电器4",3);
    }
}

void MainWindow::If1Or3BreakSucess()
{
    if(currentPart==1)
    {
        if(switchControl.controlValue.onOff[0]==false)
        {
            TableWidgetAddRow("断开继电器1成功",3);
        }
        else
        {
            TableWidgetAddRow("断开继电器1失败",3);
            ShowTestFailed(1,"测试失败");
            device1IsFinish2=true;
            device1IsSuccess2=false;
        }
    }
    else if(currentPart==2)
    {
        if(switchControl.controlValue.onOff[2]==false)
        {
            TableWidgetAddRow("断开继电器3成功",3);
        }
        else
        {
            TableWidgetAddRow("断开继电器3失败",3);
            ShowTestFailed(1,"测试失败");
            device1IsFinish2=true;
            device1IsSuccess2=false;
        }
    }
}

void MainWindow::If2OR4BreakSucess()
{
    if(currentPart==1)
    {
        if(switchControl.controlValue.onOff[1]==false)
        {
            TableWidget2AddRow("断开继电器2成功",3);
        }
        else
        {
            TableWidget2AddRow("断开继电器2失败",3);
            ShowTestFailed(2,"测试失败");
            device2IsFinish2=true;
            device2IsSuccess2=false;
        }
    }
    else if(currentPart==2)
    {
        if(switchControl.controlValue.onOff[3]==false)
        {
            TableWidget2AddRow("断开继电器4成功",3);
        }
        else
        {
            TableWidget2AddRow("断开继电器4失败",3);
            ShowTestFailed(2,"测试失败");
            device2IsFinish2=true;
            device2IsSuccess2=false;
        }
    }
}

void MainWindow::SetDevice1RangeChannel1()
{
    if(ui->comboBox_11->currentIndex()==0)
    {
        Device1->SetChannel1Range(70);
        TableWidgetAddRow("设置通道1量程70",3);
        QThread::msleep(10);
    }
    else if(ui->comboBox_11->currentIndex()==1)
    {
        Device1->SetChannel1Range(60);
        TableWidgetAddRow("设置通道1量程60",3);
        QThread::msleep(10);
    }
}

void MainWindow::SetDevice2RangeChannel1()
{
    if(ui->comboBox_11->currentIndex()==0)
    {
        Device2->SetChannel1Range(70);
        TableWidget2AddRow("设置通道1量程70",3);
    }
    else if(ui->comboBox_11->currentIndex()==1)
    {
        Device2->SetChannel1Range(60);
        TableWidget2AddRow("设置通道1量程60",3);
    }
}

void MainWindow::SetDevice1RangeChannel2()
{
    if(ui->comboBox_11->currentIndex()==0)
    {
        Device1->SetChannel2Range(70);
        TableWidgetAddRow("设置通道2量程70",3);
    }
    else if(ui->comboBox_11->currentIndex()==1)
    {
        Device1->SetChannel2Range(60);
        TableWidgetAddRow("设置通道2量程60",3);
    }
}

void MainWindow::SetDevice2RangeChannel2()
{
    if(ui->comboBox_11->currentIndex()==0)
    {
        Device2->SetChannel2Range(70);
        TableWidget2AddRow("设置通道2量程70",3);

    }
    else if(ui->comboBox_11->currentIndex()==1)
    {
        Device2->SetChannel2Range(60);
        TableWidget2AddRow("设置通道2量程60",3);
    }
}

void MainWindow::SetDevice1DeviceType()
{

    Device1->SetDeviceType(ui->comboBox_8->currentIndex());
    TableWidgetAddRow("设置产品选型"+ui->comboBox_8->currentText(),3);

}

void MainWindow::SetDevice2DeviceType()
{
    Device2->SetDeviceType(ui->comboBox_8->currentIndex());
    TableWidget2AddRow("设置产品选型"+ui->comboBox_8->currentText(),3);
}

void MainWindow::Device1Channel1ZeroCalibration()
{
    Device1->Channel1ZeroCalibration();
    TableWidgetAddRow("通道1输入零点校准",1);
}

void MainWindow::Device2Channel1ZeroCalibration()
{
    Device2->Channel1ZeroCalibration();
    TableWidget2AddRow("通道1输入零点校准",1);
}

void MainWindow::Device1Channel2ZeroCalibration()
{
    TableWidgetAddRow("通道2输入零点校准",2);
    Device1->Channel2ZeroCalibration();
}

void MainWindow::Device2Channel2ZeroCalibration()
{
    Device2->Channel2ZeroCalibration();
    TableWidget2AddRow("通道2输入零点校准",2);
}

void MainWindow::Device1OpenSwitch()
{
    if(currentPart==1)
    {
        OpenSwitch1();
        TableWidgetAddRow("闭合继电器1",3);
    }
    else if (currentPart==2)
    {
        OpenSwitch3();
        TableWidgetAddRow("闭合继电器3",3);
    }

}

void MainWindow::Device2OpenSwicth()
{
    if(currentPart==1)
    {
        OpenSwitch2();
        TableWidget2AddRow("闭合继电器2",3);

    }
    else if (currentPart==2)
    {
        OpenSwitch4();
        TableWidget2AddRow("闭合继电器4",3);
    }


}

void MainWindow::Device1Sleep500ms()
{
    QThread::msleep(500);
    TableWidgetAddRow("休眠1s",3);
}

void MainWindow::Device2Sleep500ms()
{
    QThread::msleep(500);
    TableWidget2AddRow("休眠1s",3);
}

void MainWindow::If1Or3OpenSucess()
{
    if(currentPart==1)
    {
        if(switchControl.controlValue.onOff[0]==true)
        {
            TableWidgetAddRow("闭合继电器1成功",3);
        }
        else
        {
            TableWidgetAddRow("闭合继电器1失败",3);
            ShowTestFailed(1,"测试失败");
            device1IsSuccess2=false;
            device1IsFinish2=true;

        }

    }
    else if(currentPart==2)
    {
        if(switchControl.controlValue.onOff[2]==true)
        {
            TableWidgetAddRow("闭合继电器3成功",3);
        }
        else
        {
            TableWidgetAddRow("闭合继电器3失败",3);
            ShowTestFailed(1,"测试失败");
            device1IsSuccess2=false;
            device1IsFinish2=true;
        }
    }

}

void MainWindow::If2Or4OpenSucess()
{
    if(currentPart==1)
    {
        if(switchControl.controlValue.onOff[1]==true)
        {
            TableWidget2AddRow("闭合继电器2成功",3);
        }
        else
        {
            TableWidget2AddRow("闭合继电器2失败",3);
            ShowTestFailed(2,"测试失败");
            device2IsSuccess2=false;
            device2IsFinish2=true;
        }
    }
    else if(currentPart==2)
    {

        if(switchControl.controlValue.onOff[3]==true)
        {
            TableWidget2AddRow("闭合继电器4成功",3);
        }
        else
        {
            TableWidget2AddRow("闭合继电器4失败",3);
            ShowTestFailed(2,"测试失败");
            device2IsSuccess2=false;
            device2IsFinish2=true;
        }
    }

}

void MainWindow::Device1Channel1VerifyFull()
{
    if(ui->comboBox_11->currentIndex()==0)
        Device1->Channel1InputFullCalibration(7000);
    else if(ui->comboBox_11->currentIndex()==1)
        Device1->Channel1InputFullCalibration(6000);
    TableWidgetAddRow("输入通道1较满值",1);
}

void MainWindow::Device2Channel1VerifyFull()
{
    if(ui->comboBox_11->currentIndex()==0)
        Device2->Channel1InputFullCalibration(7000);
    else if(ui->comboBox_11->currentIndex()==1)
        Device2->Channel1InputFullCalibration(6000);
    TableWidget2AddRow("输入通道1较满值",1);
}

void MainWindow::Device1Channel2VerifyFull()
{
    if(ui->comboBox_11->currentIndex()==0)
        Device1->Channel2InputFullCalibration(7000);
    else if(ui->comboBox_11->currentIndex()==1)
        Device1->Channel2InputFullCalibration(6000);
    TableWidgetAddRow("输入通道2较满值",2);
}

void MainWindow::Device2Channel2VerifyFull()
{
    if(ui->comboBox_11->currentIndex()==0)
        Device2->Channel2InputFullCalibration(7000);
    else if(ui->comboBox_11->currentIndex()==1)
        Device2->Channel2InputFullCalibration(6000);
    TableWidget2AddRow("输入通道2较满值",2);
}

void MainWindow::Device1Channel1ZeroOutPutTest(int value)
{
    Device1->Channel1ZeroAdjustment(value);
    TableWidgetAddRow(QString("零点调试控制输出%0").arg(value),1);
}

void MainWindow::Device2Channel1ZeroOutPutTest(int value)
{
    Device2->Channel1ZeroAdjustment(value);
    TableWidget2AddRow(QString("零点调试控制输出%0").arg(value),1);
}

void MainWindow::Device1GetFirstPoint(int channel)
{
    firstPoint1=adCollector.GetCurrentValue();

    float readValue=0;
    if(currentPart==1)
    {
        if(channel==1)
        {
            readValue=firstPoint1.readValue[0];
        }
        else if(channel==2)
        {
            readValue=firstPoint1.readValue[2];
        }
    }
    else if(currentPart==2)
    {
        if(channel==1)
        {
            readValue=firstPoint1.readValue[4];
        }
        else if(channel==2)
        {
            readValue=firstPoint1.readValue[6];
        }
    }
    TableWidgetAddRow(QString("第1点获取输出电压/电流%0").arg(readValue),channel);
}

void MainWindow::Device2GetFirstPoint(int channel)
{
    firstPoint2=adCollector.GetCurrentValue();
    float readValue=0;
    if(currentPart==1)
    {
        if(channel==1)
        {
            readValue=firstPoint2.readValue[1];
        }
        else if(channel==2)
        {
            readValue=firstPoint2.readValue[3];
        }
    }
    else if(currentPart==2)
    {
        if(channel==1)
        {
            readValue=firstPoint2.readValue[5];
        }
        else if(channel==2)
        {
            readValue=firstPoint2.readValue[7];
        }
    }
    TableWidget2AddRow(QString("第1点获取输出电压/电流%0").arg(readValue),channel);

}

void MainWindow::Device1GetSecondPoint(int channel)
{
    secondPoint1=adCollector.GetCurrentValue();

    float readValue=0;
    if(currentPart==1)
    {
        if(channel==1)
        {
            readValue=secondPoint1.readValue[0];
        }
        else if(channel==2)
        {
            readValue=secondPoint1.readValue[2];
        }
    }
    else if(currentPart==2)
    {
        if(channel==1)
        {
            readValue=secondPoint1.readValue[4];
        }
        else if(channel==2)
        {
            readValue=secondPoint1.readValue[6];
        }
    }
    TableWidgetAddRow(QString("第2点获取输出电压/电流%0").arg(readValue),channel);

}

void MainWindow::Device2GetSecondPoint(int channel)
{
    secondPoint2=adCollector.GetCurrentValue();
    float readValue=0;
    if(currentPart==1)
    {
        if(channel==1)
        {
            readValue=secondPoint2.readValue[1];
        }
        else if(channel==2)
        {
            readValue=secondPoint2.readValue[3];
        }
    }
    else if(currentPart==2)
    {
        if(channel==1)
        {
            readValue=secondPoint2.readValue[5];
        }
        else if(channel==2)
        {
            readValue=secondPoint2.readValue[7];
        }
    }
    TableWidget2AddRow(QString("第2点获取输出电压/电流%0").arg(readValue),channel);
}

void MainWindow::Device1Channel1ZeroOutPutVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)
            zeroPonit1x=ReVerify0(0,firstPoint1.readValue[0],1,secondPoint1.readValue[0],100);
        else if(currentPart==2)
            zeroPonit1x=ReVerify0(0,firstPoint1.readValue[4],1,secondPoint1.readValue[4],100);

        Device1->Channel1ZeroAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
    }
    else if(workMode==1)
    {
        if(currentPart==1)
            zeroPonit1x=ReVerify0(4,firstPoint1.readValue[0],1,secondPoint1.readValue[0],100);
        else if(currentPart==2)
            zeroPonit1x=ReVerify0(4,firstPoint1.readValue[4],1,secondPoint1.readValue[4],100);

        Device1->Channel1ZeroAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
    }

}

void MainWindow::Device2Channel1ZeroOutPutVerify()
{
    if(workMode==0)
    {

        if(currentPart==1)
            zeroPonit2x=ReVerify0(0,firstPoint2.readValue[1],1,secondPoint2.readValue[1],100);
        else if(currentPart==2)
            zeroPonit2x=ReVerify0(0,firstPoint2.readValue[5],1,secondPoint2.readValue[5],100);

        Device2->Channel1ZeroAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);
    }
    else if(workMode==1)
    {

        if(currentPart==1)
            zeroPonit2x=ReVerify0(4,firstPoint2.readValue[1],1,secondPoint2.readValue[1],100);
        else if(currentPart==2)
            zeroPonit2x=ReVerify0(4,firstPoint2.readValue[5],1,secondPoint2.readValue[5],100);

        Device2->Channel1ZeroAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);

    }

}

void MainWindow::Device1JudgeChannelOutPutVerify(int channel, int zero)
{
    //获取采集板上的value
    RecvAdValue value=adCollector.GetCurrentValue();
    //workMode=0为电压模式
    if(workMode==0)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==2)
                readValue=value.readValue[2];//设备1的通道2
            else if(channel==1)
                readValue=value.readValue[0];//设备1的通道1
        }
        else if(currentPart==2)
        {
            if(channel==2)
                readValue=value.readValue[6];//第二组 设备1的通道2
            else if(channel==1)
                readValue=value.readValue[4];//第二组 设备1的通道1
        }

        float target=0.00;
        if(zero==1)
            target=0;                       //0点校准
        else if(zero==2)
            target=5;                       //满值校准

        if(abs(readValue-target)<0.005)
        {
            TableWidgetAddRow(QString("成功,通道%0零点校准%1").arg(channel).arg(readValue),channel);
        }
        else
        {
            TableWidgetAddRow(QString("失败,通道%0零点校准%1").arg(channel).arg(readValue),channel);
            if(HaveTryTime(channel,zero))
            {
                innerStep1=GoToStep(channel,zero);
                return;
            }
            ShowTestFailed(1,"测试失败");
            device1IsSuccess2=false;
            device1IsFinish2=true;
        }
    }
    else if(workMode==1)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==2)
                readValue=value.readValue[2]; //设备1的通道2
            else if(channel==1)
                readValue=value.readValue[0]; //设备1的通道1
        }
        else if(currentPart==2)
        {
            if(channel==2)
                readValue=value.readValue[6]; //第二部分的设备1的通道2
            else if(channel==1)
                readValue=value.readValue[4];//第二部分设备1的通道1
        }
        float target=0;
        if(zero==1)
            target=4;                       //零点4mA
        else if(zero==2)
            target=20;                      //满值20mA

        if(abs(readValue-target)<0.016)
        {
            TableWidgetAddRow(QString("成功,通道%0校准%1").arg(channel).arg(readValue),channel);
        }
        else
        {
            TableWidgetAddRow(QString("失败,通道%0校准%1").arg(channel).arg(readValue),channel);
            if(HaveTryTime(channel,zero))
            {
                innerStep1=GoToStep(channel,zero);
                return;
            }
            device1IsFinish2=true;
            device1IsSuccess2=false;
            ShowTestFailed(1,"测试失败");
        }
    }
}

void MainWindow::Device2JudgeChannelOutPutVerify(int channel, int zero)
{
    RecvAdValue value=adCollector.GetCurrentValue();
    if(workMode==0)
    {
        float readValue=0;
        if(currentPart==1)
        {
            if(channel==2)
                readValue=value.readValue[3];
            else if(channel==1)
                readValue=value.readValue[1];
        }
        else if(currentPart==2)
        {
            if(channel==2)
                readValue=value.readValue[7];
            else if(channel==1)
                readValue=value.readValue[5];
        }

        float target=0;
        if(zero==1)
            target=0;
        else if(zero==2)
            target=5;

        if(abs(readValue-target)<0.005)
        {
            TableWidget2AddRow(QString("成功,通道%0零点校准%1").arg(channel).arg(readValue),channel);
        }
        else
        {
            TableWidget2AddRow(QString("失败,通道%0零点校准%1").arg(channel).arg(readValue),channel);
            if(HaveTryTime(channel,zero))
            {
                innerStep2=GoToStep(channel,zero);
                return;
            }
            device2IsSuccess2=false;
            device2IsFinish2=true;
            ShowTestFailed(2,"测试失败");
        }
    }
    else if(workMode==1)
    {

        float readValue=0;
        if(currentPart==1)
        {
            if(channel==2)
                readValue=value.readValue[3];
            else if(channel==1)
                readValue=value.readValue[1];
        }
        else if(currentPart==2)
        {
            if(channel==2)
                readValue=value.readValue[7];
            else if(channel==1)
                readValue=value.readValue[5];
        }

        float target=0;
        if(zero==1)
            target=4;
        else if(zero==2)
            target=20;

        if(abs(readValue-target)<0.016)
        {
            TableWidget2AddRow(QString("成功,通道%0校准%1").arg(channel).arg(readValue),channel);
        }
        else
        {
            TableWidget2AddRow(QString("失败,通道%0校准%1").arg(channel).arg(readValue),channel);
            if(HaveTryTime(channel,zero))
            {
                innerStep2=GoToStep(channel,zero);
                return;
            }
            device2IsSuccess2=false;
            device2IsFinish2=true;
            ShowTestFailed(2,"测试失败");
        }
    }

}

void MainWindow::Device1Channel1FullOutPutTest(int value)
{
    Device1->Channel1FullAdjustment(value);
    TableWidgetAddRow(QString("通道1满值调试输出电压值%0").arg(value),1);
}

void MainWindow::Device2Channel1FullOutPutTest(int value)
{
    Device2->Channel1FullAdjustment(value);
    TableWidget2AddRow(QString("通道1满值调试输出电压值%0").arg(value),1);
}

void MainWindow::Device1Channel1FullOutPutVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)
            zeroPonit1x=ReVerify0(5,firstPoint1.readValue[0],1,secondPoint1.readValue[0],100);
        else if(currentPart==2)
            zeroPonit1x=ReVerify0(5,firstPoint1.readValue[4],1,secondPoint1.readValue[4],100);
        Device1->Channel1FullAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);


    }
    else if(workMode==1)
    {
        if(currentPart==1)
            zeroPonit1x=ReVerify0(20,firstPoint1.readValue[0],1,secondPoint1.readValue[0],100);
        else if(currentPart==2)
            zeroPonit1x=ReVerify0(20,firstPoint1.readValue[4],1,secondPoint1.readValue[4],100);
        Device1->Channel1FullAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),1);
    }

}

void MainWindow::Device2Channel1FullOutPutVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)
            zeroPonit2x=ReVerify0(5,firstPoint2.readValue[1],1,secondPoint2.readValue[1],100);
        else if (currentPart==2)
        {
            zeroPonit2x=ReVerify0(5,firstPoint2.readValue[5],1,secondPoint2.readValue[5],100);
        }
        Device2->Channel1FullAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);
    }
    else if(workMode==1)
    {

        if(currentPart==1)
        {
            zeroPonit2x=ReVerify0(20,firstPoint2.readValue[1],1,secondPoint2.readValue[1],100);
        }
        else if(currentPart==2)
            zeroPonit2x=ReVerify0(20,firstPoint2.readValue[5],1,secondPoint2.readValue[5],100);
        Device2->Channel1FullAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),1);


    }

}

void MainWindow::Device1SaveChannel(int channel)
{
    if(channel==1)
    {
        Device1->SaveChannel1();
        TableWidgetAddRow("保存通道1",1);
    }
    else if(channel==2)
    {
        Device1->SaveChannel2();
        TableWidgetAddRow("保存通道2",2);
        TableWidgetAddRow("Success",3,Qt::green);
    }
}

void MainWindow::Device2SaveChannel(int channel)
{
    if(channel==1)
    {
        TableWidget2AddRow("保存通道1",1);
        Device2->SaveChannel1();
    }
    else if(channel==2)
    {
        TableWidget2AddRow("保存通道2",2);
        Device2->SaveChannel2();
        TableWidget2AddRow("Success",3,Qt::green);

    }
}

void MainWindow::Device1Channel2ZeroOutputTest(int value)
{
    Device1->Channel2ZeroAdjustment(value);
    TableWidgetAddRow(QString("零点调试控制输出%0").arg(value),2);

}

void MainWindow::Device2Channel2ZeroOutputTest(int value)
{
    Device2->Channel2ZeroAdjustment(value);
    TableWidget2AddRow(QString("零点调试控制输出%0").arg(value),2);
}

void MainWindow::Device1Channel2ZeroOutputVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)//01 23 45 67
            zeroPonit1x=ReVerify0(0,firstPoint1.readValue[2],1,secondPoint1.readValue[2],100);
        else if(currentPart==2)
            zeroPonit1x=ReVerify0(0,firstPoint1.readValue[6],1,secondPoint1.readValue[6],100);

        Device1->Channel2ZeroAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),2);
    }
    else if(workMode==1)
    {
        if(currentPart==1)
            zeroPonit1x=ReVerify0(4,firstPoint1.readValue[2],1,secondPoint1.readValue[2],100);
        else if(currentPart==2)
        {
            zeroPonit1x=ReVerify0(4,firstPoint1.readValue[6],1,secondPoint1.readValue[6],100);
        }
        Device1->Channel2ZeroAdjustment(zeroPonit1x);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(zeroPonit1x),2);
    }

}

void MainWindow::Device2Channel2ZeroOutputVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)
            zeroPonit2x=ReVerify0(0,firstPoint2.readValue[3],1,secondPoint2.readValue[3],100);
        else if(currentPart==2)
        {
            zeroPonit2x=ReVerify0(0,firstPoint2.readValue[7],1,secondPoint2.readValue[7],100);
        }
        Device2->Channel2ZeroAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),2);

    }
    else if(workMode==1)
    {

        if(currentPart==1)
            zeroPonit2x=ReVerify0(4,firstPoint2.readValue[3],1,secondPoint2.readValue[3],100);
        else if(currentPart==2)
            zeroPonit2x=ReVerify0(4,firstPoint2.readValue[7],1,secondPoint2.readValue[7],100);
        Device2->Channel2ZeroAdjustment(zeroPonit2x);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(zeroPonit2x),2);
    }


}

void MainWindow::Device1Channel2FullOutputTest(int value)
{
    Device1->Channel2FullAdjustment(value);
    TableWidgetAddRow(QString("满值调试控制输出%0").arg(value),2);
}

void MainWindow::Device2Channel2FullOutputTest(int value)
{
    Device2->Channel2FullAdjustment(value);
    TableWidget2AddRow(QString("满值调试控制输出%0").arg(value),2);
}

void MainWindow::Device1Channel2FullOutputVerify()
{
    if(workMode==0)
    {
        if(currentPart==1)
        {
            fullPointx1=ReVerify0(5.00,firstPoint1.readValue[2],1,secondPoint1.readValue[2],100);
        }
        else if(currentPart==2)
        {
            fullPointx1=ReVerify0(5.00,firstPoint1.readValue[6],1,secondPoint1.readValue[6],100);
        }
        Device1->Channel2FullAdjustment(fullPointx1);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(fullPointx1),2);

    }
    else if(workMode==1)
    {
        if(currentPart==1)
            fullPointx1=ReVerify0(20,firstPoint1.readValue[2],1,secondPoint1.readValue[2],100);
        else if(currentPart==2)
        {
            fullPointx1=ReVerify0(20,firstPoint1.readValue[6],1,secondPoint1.readValue[6],100);
        }
        Device1->Channel2FullAdjustment(fullPointx1);
        TableWidgetAddRow(QString("发送计算出来的校准值%0").arg(fullPointx1),2);

    }

}

void MainWindow::Device2Channel2FullOutputVerify()
{
    if(workMode==0)
    {

        if(currentPart==1)
        {
            fullPointx2=ReVerify0(5.00,firstPoint2.readValue[3],1,secondPoint2.readValue[3],100);
        }
        else if(currentPart==2)
        {
            fullPointx2=ReVerify0(5.00,firstPoint2.readValue[7],1,secondPoint2.readValue[7],100);
        }
        Device2->Channel2FullAdjustment(fullPointx2);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(fullPointx2),2);


    }
    else if(workMode==1)
    {

        if(currentPart==1)
            fullPointx2=ReVerify0(20,firstPoint2.readValue[3],1,secondPoint2.readValue[3],100);
        else if(currentPart==2)
            fullPointx2=ReVerify0(20,firstPoint2.readValue[7],1,secondPoint2.readValue[7],100);
        Device2->Channel2FullAdjustment(fullPointx2);
        TableWidget2AddRow(QString("发送计算出来的校准值%0").arg(fullPointx2),2);

    }

}

void MainWindow::TableWidgetIsClear()
{
    ui->tableWidget->clearContents();
    ui->tableWidget->setRowCount(0);
    ui->tableWidget_2->clearContents();
    ui->tableWidget_2->setRowCount(0);
}

int MainWindow::GetTime(int stepID)
{
    int ret=0;
    switch (stepID)
    {
    case 2:
    case 10:
        ret=1000;
        break;
    case 9:
        ret=500;
        break;
    case 14:
    case 16:
    case 18:
    case 20:
    case 22:
    case 24:
    case 27:
    case 29:
    case 31:
    case 33:
    case 35:
    case 37:
        ret=2000;
        break;
    default:
        ret=10;
        break;

    }
    return ret;
}



void MainWindow::SleepEnoughTime()
{
    int time1=0,time2=0;
    time1=GetTime(innerStep1);
    time2=GetTime(innerStep2);
    int timeMax=qMax(time1,time2);

    QThread::msleep(timeMax);
}

void MainWindow::TimerTimeOut2()
{
    int ret1=0,ret2=0;
    switch (testStep)
    {
    case 0:
        innerStep1=1;
        innerStep2=1;
        device1IsFinish2=false;
        device2IsFinish2=false;
        device1IsSuccess2=true;
        device2IsSuccess2=true;
        ChooseAOrBToTest2();
        break;
    case 1:
        if(device1ShouldTest)
            ret1=Device1GoToNext();
        else
            ret2=0;
        if(device2ShouldTest)
            ret2=Device2GoToNext();
        else
            ret2=0;
        qDebug()<<"进行下一步ret返回"<<ret1<<ret2;
        if(ret1==0&&ret2==0)        //如果都成功则选取下一步进行测试
        {
            testStep=0;
        }
        else if(ret1==1||ret2==1)   //如果某个没测完，则留在此阶段
        {
            testStep=1;
        }
        else if(ret1==2||ret2==2)   //如果某个测试失败，且测试完毕。则停止定时器，让用户查看状态。
        {
            testStep=2;
        }
        break;
    case 2:
        timer.stop();
        break;
    }
    SleepEnoughTime();
}

void MainWindow::GetReady()
{

    switchControl.OpenDevice(ui->comboBox_10->currentText());
    if(switchControl.modbus->port.isOpen())
    {

    }
    else
    {
        QMessageBox a;
        a.setText("准备失败，请检查串口");
        a.show();
        a.exec();
    }

    qDebug()<<__FUNCTION__;
}
void MainWindow::OpenPort()
{
    qDebug()<<__FUNCTION__;
    emit adCollector.PortOpen(ui->comboBox->currentText());
}

void MainWindow::OpenSwitchControlDevice()
{
    switchControl.OpenDevice(ui->comboBox_2->currentText());
    if(switchControl.modbus->port.isOpen())
    {
        QMessageBox a;
        a.setText("打开成功");
        a.show();
        a.exec();
    }
    else
    {
        QMessageBox a;
        a.setText("打开失败");
        a.show();
        a.exec();

    }
}

void MainWindow::ShowAdValue(float *value)
{
    ui->lineEdit->setText(QString::number(value[0],'f',4));
    ui->lineEdit_2->setText(QString::number(value[1],'f',4));
    ui->lineEdit_3->setText(QString::number(value[2],'f',4));
    ui->lineEdit_4->setText(QString::number(value[3],'f',4));

    ui->lineEdit_5->setText(QString::number(value[4],'f',4));
    ui->lineEdit_6->setText(QString::number(value[5],'f',4));
    ui->lineEdit_7->setText(QString::number(value[6],'f',4));
    ui->lineEdit_8->setText(QString::number(value[7],'f',4));
}

void MainWindow::HandleGetADValue()
{
    RecvAdValue readValue=adCollector.GetCurrentValue();
    if(readValue.isSuccess==false)
    {
        ui->textEdit->setText("始于"+readValue.startTime.toString("hh:mm:ss.zzz")+"\n");
        ui->textEdit->setText("获取失败");
        ui->textEdit->setText("终于"+readValue.endTime.toString("hh:mm:ss.zzz")+"\n");

    }
    else
    {
        QString showValue;
        showValue+="始于"+readValue.startTime.toString("hh:mm:ss.zzz")+"\n";
        for(int i=0;i<=7;i++)
            showValue+=QString("第%0通道%1V\n").arg(QString::number(i)).arg(QString::number(readValue.readValue[i],'f',4));
        showValue+="终于"+readValue.endTime.toString("hh:mm:ss.zzz")+"\n";
        ui->textEdit->setText(showValue);
    }

}

void MainWindow::OpenSwitch1()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(200);
    }
    switchControl.SetSwitchOnOff(0,true);
    QThread::msleep(300);
    switchControl.StartTimer();
}

void MainWindow::OpenSwitch2()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(200);
    }
    switchControl.SetSwitchOnOff(1,true);
    QThread::msleep(300);
    switchControl.StartTimer();
}

void MainWindow::OpenSwitch3()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(200);
    }
    switchControl.SetSwitchOnOff(2,true);
    QThread::msleep(300);
    switchControl.StartTimer();
}

void MainWindow::OpenSwitch4()
{
    qDebug()<<__FUNCTION__;
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(200);
    }
    switchControl.SetSwitchOnOff(3,true);
    QThread::msleep(300);
    switchControl.StartTimer();
}

void MainWindow::CloseSwitch1()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(400);
    }
    switchControl.SetSwitchOnOff(0,false);
    QThread::msleep(400);
    switchControl.StartTimer();
}

void MainWindow::CloseSwitch2()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(400);
    }
    switchControl.SetSwitchOnOff(1,false);
    QThread::msleep(400);
    switchControl.StartTimer();
}

void MainWindow::CloseSwitch3()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(400);
    }
    switchControl.SetSwitchOnOff(2,false);
    QThread::msleep(400);
    switchControl.StartTimer();
}

void MainWindow::CloseSwitch4()
{
    switchControl.StopTimer();
    while (switchControl.isRunning)
    {
        QThread::msleep(400);
    }
    switchControl.SetSwitchOnOff(3,false);
    QThread::msleep(400);
    switchControl.StartTimer();
}

void MainWindow::StartAsk()
{
    if(ui->checkBox->isChecked())
    {
        switchControl.StartTimer();
    }
    else {
        switchControl.StopTimer();
    }

}

void MainWindow::GetSwitchInputValue()
{
    SwitchInput value=switchControl.GetAllInputValue();
    qDebug()<<value.success<<value.onOff[0]<<value.onOff[1]<<value.onOff[2]<<value.onOff[3];
    if(value.success)
    {
        if(value.onOff[0])
        {
            ui->lineEdit_13->setText("闭合");
        }
        else
            ui->lineEdit_13->setText("断开");

        if(value.onOff[1])
        {
            ui->lineEdit_14->setText("闭合");
        }
        else
            ui->lineEdit_14->setText("断开");

        if(value.onOff[2])
        {
            ui->lineEdit_15->setText("闭合");
        }
        else
            ui->lineEdit_15->setText("断开");

        if(value.onOff[3])
        {
            ui->lineEdit_16->setText("闭合");
        }
        else
            ui->lineEdit_16->setText("断开");
    }
}

void MainWindow::GetSwitchControlValue()
{
    SwitchControlValue controlValue=switchControl.GetAllControlValue();
    if(controlValue.sucess)
    {
        if(controlValue.onOff[0])
        {
            ui->lineEdit_9->setText("闭合");
        }
        else
            ui->lineEdit_9->setText("断开");

        if(controlValue.onOff[1])
        {
            ui->lineEdit_10->setText("闭合");
        }
        else
            ui->lineEdit_10->setText("断开");

        if(controlValue.onOff[2])
        {
            ui->lineEdit_11->setText("闭合");
        }
        else
            ui->lineEdit_11->setText("断开");

        if(controlValue.onOff[3])
        {
            ui->lineEdit_12->setText("闭合");
        }
        else
            ui->lineEdit_12->setText("断开");
    }
}

void MainWindow::OpenDevice()
{
    qDebug()<<__FUNCTION__;
    myDevice.OpenDevice(ui->comboBox_3->currentText(),9600);
    if(myDevice.modbus->port.isOpen())
    {
        QMessageBox a;
        a.setText("打开成功");
        a.show();
        a.exec();
    }
    else
    {
        QMessageBox a;
        a.setText("打开失败");
        a.show();
        a.exec();
    }
}

void MainWindow::SendFc6ToDevice()
{
    short value=1;
    myDevice.SendFc6(1,0x04b1,1,&value);
}

void MainWindow::TimerTimeOut()
{
    qDebug()<<__FUNCTION__;
    switch (steps)
    {
    case 0://选取要测试的是B组还是A组
        ChooseAOrBToTest();
        device1IsSuccees=true;
        device2IsSuccees=true;
        break;
    case 1://断开继电器
        BreakSwitch();
        steps++;
        break;
    case 2://判断继电器是否断开成功
        JudgeIfBreakSwitchSuccess();
        steps++;
        break;
    case 3://设置通道1的量程
        SetDeviceRangeChannel1();
        steps++;
        break;

    case 4://设置通道2的量程
        SetDeviceRangeChannel2();
        steps++;
        break;
    case 5://设置设备类型
        SetDeviceType();
        steps++;
        break;
    case 6://通道1零点校准
        Channel1ZeroCalibration();
        steps++;
        break;
    case 7://通道2零点校准
        Channel2ZeroCalibration();
        steps++;
        break;
    case 8://闭合继电器
        OpenSwitch();
        steps++;
        break;
    case 9:
        Sleep2S();
        steps++;
        break;
    case 10:
        JudgeIfOpenSwitchSuccess();
        break;
    case 11:
        Channel1VerifyFull();
        steps++;
        break;
    case 12:
        Channel2VerifyFull();
        steps++;
        break;
    case 13://零点调试输出1
        Channel1ZeroOutPutTest(1);
        steps++;
        break;
    case 14://读取零点调试输出的电压值
        GetFirstPoint(1);
        break;
    case 15://零点调试输出100
        Channel1ZeroOutPutTest(100);
        steps++;
        break;
    case 16://读取零点调试的电压值
        GetSecondPoint(1);
        break;
    case 17://校验0点
        //设备1设备2 1通道零点
        Channel1ZeroOutPutVerify();
        steps++;

        break;
    case 18:
        JudgeChannelOutputVerifySuccess(1,1);
        break;
    case 19://设备1 2通道1较满值
        Channel1FullOutPutTest(1);
        steps++;
        break;
    case 20:
        GetFirstPoint(1);
        break;
    case 21:
        Channel1FullOutPutTest(100);
        steps++;
        break;
    case 22:
        GetSecondPoint(1);
        break;
    case 23:
        Channel1FullOutputVerify();
        steps++;
        break;
    case 24:
        JudgeChannelOutputVerifySuccess(1,2);

        break;
    case 25:
        SaveChannel(1);
        steps++;
        break;
    case 26:
        Channel2ZeroOutputTest(1);
        steps++;
        break;
    case 27:
        GetFirstPoint(2);
        break;
    case 28://两个设备的第二通道较零
        Channel2ZeroOutputTest(100);
        steps++;
        break;
    case 29:
        GetSecondPoint(2);
        break;
    case 30:
        Channel2ZeroOutputVerify();
        steps++;
        break;
    case 31:
        JudgeChannelOutputVerifySuccess(2,1);
        break;
    case 32:
        Channel2FullOutputTest(1);
        steps++;
        break;
    case 33:
        GetFirstPoint(2);
        break;
    case 34:
        Channel2FullOutputTest(100);
        steps++;
        break;
    case 35:
        GetSecondPoint(2);
        break;
    case 36:
        Channel2FullOutputVerify();
        steps++;
        break;
    case 37:
        JudgeChannelOutputVerifySuccess(2,2);
        break;
    case 38:

        SaveChannel(2);
        if(device1IsSuccees==false||device2IsSuccees==false)
            timer.stop();
        steps=0;
        break;
    }
}

void MainWindow::Start()
{
    qDebug()<<__FUNCTION__<<__LINE__;
    timer.stop();
    steps=0;
    adCollector.StopTimer();
    tryTimes11=2;
    tryTimes12=2;
    tryTimes21=2;
    tryTimes22=2;

    qDebug()<<__FUNCTION__<<__LINE__;
    DeviceA1.OpenDevice(ui->comboBox_4->currentText(),9600);
    qDebug()<<__FUNCTION__<<__LINE__;
    if(DeviceA1.modbus->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        qDebug()<<"~~~";
        set.setValue("port1",ui->comboBox_4->currentText());
        set.endGroup();
    }
    qDebug()<<__FUNCTION__<<__LINE__;
    DeviceA2.OpenDevice(ui->comboBox_5->currentText(),9600);
    if(DeviceA2.modbus->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        set.setValue("port2",ui->comboBox_5->currentText());
        set.endGroup();
    }
    DeviceB1.OpenDevice(ui->comboBox_6->currentText(),9600);
    if(DeviceB1.modbus->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        set.setValue("port3",ui->comboBox_6->currentText());
        set.endGroup();
    }
    DeviceB2.OpenDevice(ui->comboBox_7->currentText(),9600);
    if(DeviceB2.modbus->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        set.setValue("port4",ui->comboBox_7->currentText());
        set.endGroup();
    }

    adCollector.OpenPort(ui->comboBox_19->currentText());
    if(adCollector.modBusDevice->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        set.setValue("portad",ui->comboBox_19->currentText());
        set.endGroup();
        qDebug()<<"port ad open success";
    }
    else
    {

        qDebug()<<__FUNCTION__<<__LINE__<<"Serial port is not open";
    }

    switchControl.OpenDevice(ui->comboBox_10->currentText());

    if(switchControl.modbus->port.isOpen())
    {
        QSettings set("SerialPortConfig.ini",QSettings::IniFormat);
        set.beginGroup("Value");
        set.setValue("portswitch",ui->comboBox_10->currentText());
        set.endGroup();
        qDebug()<<"port ad open success";
    }
    else
    {
        qDebug()<<__FUNCTION__<<__LINE__<<"Serial port is not open";
    }

    ui->comboBox_4->setEnabled(false);
    ui->comboBox_5->setEnabled(false);
    ui->comboBox_6->setEnabled(false);
    ui->comboBox_7->setEnabled(false);
    ui->comboBox_19->setEnabled(false);

    if(ui->comboBox_9->currentIndex()==0)
    {
        qDebug()<<__LINE__<<__FUNCTION__;
        adCollector.SwitchToVotagetValue();
        qDebug()<<__LINE__<<__FUNCTION__;
    }
    else if(ui->comboBox_9->currentIndex()==1)
    {
        adCollector.SwitchToCurrentValue();
    }
    QThread::msleep(300);
    qDebug()<<__FUNCTION__<<__LINE__<<workMode;
    workMode=adCollector.GetWorkMode();
    qDebug()<<__FUNCTION__<<__LINE__<<workMode;
    if(workMode==0)
    {
        ui->lineEdit_33->setText("电压");
    }
    else if(workMode==1)
    {
        ui->lineEdit_33->setText("电流");
    }
    ui->tableWidget->setRowCount(0);
    ui->tableWidget_2->setRowCount(0);
    timer.start(700);

    //初始化步骤
    testStep=0;
}

void MainWindow::CurrentMode()
{
    adCollector.SwitchToCurrentValue();
}

void MainWindow::VoltageMode()
{
    adCollector.SwitchToVotagetValue();
}

void MainWindow::ZeroVerify()
{
    qDebug()<<__FUNCTION__;
    DeviceA1.Channel1ZeroAdjustment(ui->spinBox->value());

}

void MainWindow::ShowBumb(int value)
{
    if(value==1)
    {
        QImage m(":picture/green.jpeg");
        m=m.scaledToWidth(ui->label_23->width());
        ui->label_23->setPixmap(QPixmap::fromImage(m));
    }
    else if(value==2)
    {
        QImage m(":picture/green.jpeg");
        m=m.scaledToWidth(ui->label_24->width());
        ui->label_24->setPixmap(QPixmap::fromImage(m));
    }

}


void MainWindow::on_pushButton_18_clicked()
{
    timer.stop();
}
